<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="" id="app">

        <div>{{words}}</div>
        <button @click="words+=1">按钮</button>
        <div>{{obj.words}}</div>
        <button @click="obj.age+=1">按钮</button>
    </div>


    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                words: '苹果',
                obj: {
                    words: '香蕉',
                    age: 18
                }
            },
            methods: {},
            computed: {},
            watch: {
                words(newV, oldV) {
                    console.log('变化了  ----->  ', newV, oldV);
                },
                obj: {
                    handler(newV, oldV) {
                        console.log('obj变化了  ----->  ', JSON.stringify(newV), JSON.stringify(oldV));
                    },
                    deep: true,
                    // immediate: true
                },
                // 单独监听对象的某个属性
                'obj.age'(newV, oldV) {
                    console.log('obj.age变化了  ----->  ', newV, oldV);
                }
            }
        })
    </script>
</body>

</html>